<script type="text/javascript">

	function editSession()
	{
			document.manageForm.action = "editSession.php"
			document.manageForm.submit();
	}
</script>
	
<?php

	$userID = $_SESSION['userId'];
	
	error_reporting(0);
	$delMsg = '';
	$delMsg = $_GET['delMsg'];
	
	$con = mysql_connect("localhost", "group5", "group5");
    if(!$con)
    {
		echo "Connection failed!";
        exit;
    }
	
	
	
	mysql_select_db("group5");
	echo "<h3>Workshops you've created:</h3>";
	echo "<table class='table table-striped table-bordered table-condensed'><thead>
		<tr>
		<th>Session #</th>
		<th>Session Name</th>
		<th>Description</th>
		<th>Meeting Time</th>
		<th>Date</th>
		<th>Building</th>
		<th>Room #</th>
		<th>Edit</th>
		<th>Delete</th>
		</tr></thead><tbody>";
		
		
	$table = mysql_query("select * from WORKSHOP_SESSIONS where instructorId = $userID", $con);
	
	
	
	while($getRow = mysql_fetch_row($table))
	{
	//workshopSessionId = 0;
	//meetingTime = 1;
	//meetingDay = 2
	//workshopId = 3
	//roomId = 4
	//instructorId = 5
	$workshopSessionId = $getRow[0];
	$meetingTime = $getRow[1];
	$meetingDay = $getRow[2];
	$workshopId = $getRow[3];
	$roomID = $getRow[4];
	$instructorId = $getRow[5];

	//Data about the name and description of a Workshop
	$titleInfo = mysql_query("select * from WORKSHOP where workshopId = $workshopId", $con);
	$getTitle = mysql_fetch_row($titleInfo);
	
	$title = $getTitle[1];
	$descrip = $getTitle[2];
	
	//Data about the room and building number of a workshop.
	$roomInfo = mysql_query("select * from ROOM where roomId = $roomID;", $con);
	$getRoom = mysql_fetch_row($roomInfo);
	
	$roomNum = $getRoom[2];
	$building = $getRoom[3];
	
			
		//Get the building name
		$buildingInfo = mysql_query("select * from BUILDING where bldgId = $building");
		$getBuilding = mysql_fetch_row($buildingInfo);
		$buildingName = $getBuilding[1];
		
	echo "<tr>
		<td>$workshopSessionId</td>
		<td>$title</td>
		<td>$descrip</td>
		<td>$meetingTime</td>
		<td>$meetingDay</td>
		<td>$buildingName</td>
		<td>$roomNum</td>
		<td><form method = 'post' action='editSession.php'><button type = 'submit' name='submit' id='submit' value ='$workshopSessionId' >Edit</button></form></td>
		<td><form method = 'post' action='deleteWorkshop.php'><button type = 'submit' name='delete' id='delete' value ='$workshopSessionId' >Delete</button></form></td>
		</tr>";
	}
		
	echo "</tbody></table>";
	

?>
<p id='delMsg'><?php echo $delMsg; ?></p>